<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>搜索结果</title>
    <link href="${contextPath}/resource/css/a4yy/index.css" rel="stylesheet" type="text/css"/>
    <#include "/common/common.ftl">
</head>
<body>
    <input id="keyBox" type="hidden" value="${param!}"/>
    <div class="tool-bar">
        <button id="goIndex">返回主页</button>
        <button id="jumpTo">跳转</button>
        <input type="text" value="1"/>
    </div>
    <div class="content">
    </div>
</body>
<script>
    $(function(){
        var key=$("#keyBox").val();
        $("#keyBox").remove();
        request(key,"1");
        $(document).on("click","div[class=content]>div",function(){
            var url=$(this).data("linked");
            location.href=basePath+"/a4yy/to/detail?param="+url;
        });
        $("#jumpTo").click(function(){
            var val=$(this).next().val();
            val=isNaN(val)?"1":val;
            //http://aaxxy.com/vod-list-id-1-pg-3-order--by--class-77-year-0-letter--area--lang-.html
            request(key,val);
        });
        $("#goIndex").click(function(){
            location.href=basePath+"/a4yy/to/index";
        });
    })

    var isRequest=false;
    function request(key,page){
        if(isRequest)return;
        isRequest=true;
        $.ajax({
            url: basePath + "/a4yy/search",
            data: {key:key,page:page},
            type: "get",
            dataType: 'json',
            success: function (data) {
                initList(data);
            },
            complete:function(){
                isRequest=false;
            }
        });
    }

    function initList(list){
        var content = $("div[class=content]");
        content.html('');
        for(var i in list){
            if(typeof(list[i])==='string' || list[i]==null){
                continue;
            }
            var info = list[i];
            var div=$("<div></div>").appendTo(content);
            div.data("linked",info.detailUrl);
            $("<div class='img' style='background-image:url("+info.imageUrl+");'></div>").appendTo(div);
            var infoContent = $("<div class='info'></div>").appendTo(div);
            var ul = $("<ul></ul>").appendTo(infoContent);
            var li=$("<li></li>").appendTo(ul);
            li.text(info.name);
            li=$("<li></li>").appendTo(ul);
            li.text("无");
        }
    }
</script>
</html>